﻿using LYR_RPA.service;
using LYR_RPA.views.ui;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Threading;

namespace LYR_RPA
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly DispatcherTimer timer;
        private int countDown = 2;

        private readonly WebSocketClient WebSocketClient;
        public MainWindow()
        {
            InitializeComponent();
            WebSocketClient = WebSocketClient.Instance;
            //Loaded += new RoutedEventHandler(Window_Loaded);
            timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            timer.Tick += Timer_Tick;
            timer.Start();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (!(FindResource("FadeInStoryboard") is Storyboard fadeInStoryboard))
            {
                return;
            }
            fadeInStoryboard.Begin(this);
        }
        private void Button_Exit(object sender, RoutedEventArgs e)
        {
            Close();
            WebSocketClient.Close();
            Application.Current.Shutdown();
        }

        private void Card_MouseDown(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            countDown--;

            if (countDown <= 0)
            {
                App.HomeWindow= new HomeWindow();
                App.HomeWindow.Show();
                timer.Stop();
                this.Close();
            }
        }

    }
}
